/*
 *  Copright: 2008 Philipp Leitner, Distributed Systems Group,
 *            TU Wien, leitner@infosys.tuwien.ac.at
 *
 *  This file is part of DAIOS.
 *
 *  DAIOS is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation.
 * 
 *  DAIOS is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with DAIOS.  If not, see
 *  <http://www.gnu.org/licenses/>.
 * 
 */

package at.ac.tuwien.infosys.dsg.daios.framework;

import at.ac.tuwien.infosys.dsg.daios.framework.structs.DaiosOutputMessage;

/**
 * A Daios Poll Object for client-side asynchrony.
 * 
 * @author philipp
 *
 */
public abstract class PollObject {
	
	// the result wrapped in this poll object
	protected DaiosOutputMessage result = null;
	
	// a possible error
	protected Exception error = null;
	
	/**
	 * Check if the response is already available.
	 * 
	 * @return True if the response is ready, false otherwise.
	 */
	public boolean responseReceived() {
		return (result != null || error != null);
	}
	
	/**
	 * Check if an error has occured.
	 * 
	 * @return True if there was an error, false otherwise.
	 */
	public boolean errorOccured() {
		return (error != null);
	}
	
	/**
	 * Fetch the result.
	 * 
	 * @return The Daios response message, null if the
	 * response is not ready yet or an error occured.
	 */
	public DaiosOutputMessage getResult() {
		return result;
	}
	
	/**
	 * Fetch the error message.
	 * 
	 * @return The error message as java.lang.Exception. Null
	 * if no error occured.
	 */
	public Exception getError() {
		return error;
	}
}
